mui.init();
var demo = new Vue({
	el: '#main',
	data: {
		taglist: []
	},
	methods: {
		deltag: deltag
	},
	ready: function() {
		var tagUrl = getUrl("61getTag");
		var tagHeader = getHeader();
		var datas = "accountId=" + readData(localStorage.account) + "&createAccountId=" + readData(localStorage.account) + "&userId=" + readData(localStorage.guideId);
		this.$http({
			url: tagUrl,
			method: 'POST',
			headers: tagHeader,
			data: datas,
			timeout: 10000
		}).then(function(respons) {
			console.log(JSON.stringify(respons.data));
			if (respons.data.code == "0") {
				if (respons.data.obj) {
					if (respons.data.obj.list) {
						var oldlist = respons.data.obj.list;
						var list = [];
						for (var i in oldlist) {
							if (parseInt(oldlist[i].tagCount) > 0) {
								list.push(oldlist[i]);
							}
						}
						if (list.length <= 0) {
							document.getElementById("tagb").style.display = "block";
						}
						this.$set('taglist', list);
					}
				}
			}
		}, function() {
			console.log('网络链接异常')
		})
	}
});

//编辑按钮的行为变化
function del(obj) {
	//val兼容 ff 识别textContent
	var val = obj.innerText || obj.textContent;
	if (obj.innerText) {
		if (val == "编辑") {
			all("block");
			obj.innerText = "取消";
		} else {
			all("none");
			obj.innerText = "编辑";
		}
	} else {
		if (val == "编辑") {
			all("block");
			obj.textContent = "取消";
		} else {
			all("none");
			obj.textContent = "编辑";
		}
	}
}
//标签删除
function deltag(tagId) {
	var btnArray = ['否', '是'];
	mui.confirm('确定要删除吗', '', btnArray, function(e) {
		if (e.index == 1) {
			var delUrl = getUrl("49delTag");
			var delHeader = getHeader();
			var datas = 'tagId=' + tagId + '&accountId=' + readData(localStorage.account);
			demo.$http({
				url: delUrl,
				method: 'POST',
				headers: delHeader,
				data: datas,
				timeout: 10000
			}).then(function(respons) {
				if (respons.data.code == "0") {
					mui.toast('删除成功');
					delet(tagId);
					var list = plus.webview.getWebviewById('friendDetail.html');
					mui.fire(list, 'add');
				} else {
					mui.toast(data.msg);
				}
			}, function() {
				console.log("删除网络异常");
			})
		}
	})

}
//block显示none隐藏删除图标
function all(str) {
	var spans = document.getElementsByTagName("span");
	for (var i = 0; i < spans.length; i++) {
		spans[i].style.display = str;
	}
}
//标签隐藏
function delet(tId) {
	document.getElementById(tId).style.display = "none"
}